package com.bw.module_store.view

import android.graphics.Color
import android.view.View
import androidx.activity.viewModels
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.bw.lib_base.path.RouterPath
import com.bw.lib_common.view.BaseMvvmActivity
import com.bw.module_store.R
import com.bw.module_store.adapter.StoreMerchantAdapter2
import com.bw.module_store.databinding.ActivityApproveStoreBinding
import com.bw.module_store.viewmodel.StoreViewModel
/**
 * 智慧园区-01-商家推荐-v1.1-吴熙-20250512
 */
@Route(path = RouterPath.PATH_APPROVE_STORE_ACTIVITY)
class ApproveStoreActivity : BaseMvvmActivity<ActivityApproveStoreBinding>() {

    lateinit var storeMerchantAdapter: StoreMerchantAdapter2
    var flag:Boolean=true
    private val viewModel : StoreViewModel by viewModels()


    override fun initViews() {
        //头布局
        mDataBinding.title.text="入驻审批"
        mDataBinding.title.setTextColor(Color.BLACK)
        mDataBinding.topbarApproveStore.setBackgroundColor(Color.WHITE)
        mDataBinding.goBack.visibility=View.GONE
        mDataBinding.goAdd.visibility=View.GONE
        mDataBinding.goBackGray.visibility=View.VISIBLE
        mDataBinding.goBackGray.setOnClickListener { finish() }

        //初始化操作
        storeMerchantAdapter= StoreMerchantAdapter2()
        mDataBinding.rv.layoutManager=LinearLayoutManager(this)
        mDataBinding.rv.adapter=storeMerchantAdapter

        viewModel.getMerchantList()

        //待确认
        mDataBinding.tvToBeConfirmed.setOnClickListener {
            mDataBinding.tvToBeConfirmed.setBackgroundResource(R.drawable.bg_btn_selected)
            mDataBinding.tvToBeConfirmed.setTextColor(Color.WHITE)
            mDataBinding.tvConfirmed.setBackgroundResource(R.drawable.bg_btn_unselect)
            mDataBinding.tvConfirmed.setTextColor(Color.GRAY)

            flag=true
            viewModel.getMerchantList()
        }

        //已确认的点击事件
        mDataBinding.tvConfirmed.setOnClickListener {
            mDataBinding.tvConfirmed.setBackgroundResource(R.drawable.bg_btn_selected)
            mDataBinding.tvConfirmed.setTextColor(Color.WHITE)
            mDataBinding.tvToBeConfirmed.setBackgroundResource(R.drawable.bg_btn_unselect)
            mDataBinding.tvToBeConfirmed.setTextColor(Color.GRAY)

            flag=false
            viewModel.getMerchantList()
        }
    }

    override fun observeDataChange() {
        viewModel.getMerchantListSuccess.observe(this){
            storeMerchantAdapter.data.clear()
            if (flag){
                storeMerchantAdapter.data.addAll(it.filter { item -> item.processingSteps[item.processingSteps.size-1].business.equals("新建")})
                storeMerchantAdapter.notifyDataSetChanged()
            }else{
                storeMerchantAdapter.data.addAll(it.filter { item -> item.processingSteps[item.processingSteps.size-1].business.equals("审核通过")})
                storeMerchantAdapter.notifyDataSetChanged()
            }

        }
    }

    override fun getLayoutId(): Int =R.layout.activity_approve_store

}